//
//  NSDictionary+GQProperty.m
//  runtime 字典转模型KVC实现
//
//  Created by sunny on 16/3/26.
//  Copyright © 2016年 sunny. All rights reserved.
//

#import "NSDictionary+GQProperty.h"

@implementation NSDictionary (GQProperty)
- (void)createProperty
{
//    创建可变的字符串,用来拼接
    NSMutableString *string = [NSMutableString string];
    
//    遍历字典,根据字典的key作为模型的属性名
    [self enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull value, BOOL * _Nonnull stop) {
        if ([value isKindOfClass:[NSString class]]) {
            [string appendFormat:@"\n@property(nonatomic,strong)NSString *%@;\n",key];
        }
        else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]) {
            [string appendFormat:@"\n@property(nonatomic,assign)BOOL %@;\n",key];
        }
        else if ([value isKindOfClass:[NSNumber class]]) {
            [string appendFormat:@"\n@property(nonatomic,assign)NSInteger %@;\n",key];
        }
        else if ([value isKindOfClass:[NSArray class]]) {
            [string appendFormat:@"\n@property(nonatomic,strong)NSArray *%@;\n",key];
        }
        else if ([value isKindOfClass:[NSDictionary class]]) {
            [string appendFormat:@"\n@property(nonatomic,strong)NSDictionary *%@;\n",key];
        }
        
    }];
    
    NSLog(@"%@",string);
}
@end
